home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / mint / bed02 / config.c < prev    next >
C/C++ Source or Header  |  1993-08-15  |  3KB  |  123 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <strings.h>
  4. #include <ctype.h>
  5. #include "missing.h"
  6. #include "bed.h"
  7.  
  8. /* $Id: config.c,v 1.2 1993/08/15 20:45:35 vincent Exp $ */
  9. /* $Log: config.c,v $
  10.  * Revision 1.2  1993/08/15  20:45:35  vincent
  11.  * fix nombre d'area (pb fgets)
  12.  * */
  13.  
  14. char *skip_blanks(char *string)
  15. {
  16.     while (*string && isspace(*string)) ++string;
  17.     return string;
  18. }
  19.  
  20. char *skip_to_blank(char *string)
  21. {
  22.         while (*string && !isspace(*string)) ++string;
  23.         return string;
  24. }
  25.  
  26. int readconfig(void)
  27. {
  28.     FILE *conf;
  29.     char temp[100], *p, *q;
  30.  
  31.     /* read tb.cfg */
  32.     sprintf (temp, "%s/tb.cfg", getenv("MAILER"));
  33.     conf=fopen(temp, "r");
  34.     if (conf==NULL)
  35.         return FALSE;
  36.     ourzone=0;
  37.     while (!feof(conf)) {
  38.         fgets (temp, 100, conf);
  39.         if (temp[strlen(temp)-1]=='\n')
  40.             temp[strlen(temp)-1]=0;
  41.         if ((!strnicmp("address", temp, 7)) && (ourzone==0)) {
  42.             /* parse only the first address line */
  43.             p=skip_blanks(temp+7);
  44.             ourpoint=0;
  45.             sscanf (p, "%d:%d/%d.%d", &ourzone, &ournet, &ournode, &ourpoint);
  46.         }
  47.         if (!strnicmp("sysop", temp, 5)) {
  48.             p=skip_blanks(temp+5);
  49.             q=skip_to_blank(p);
  50.             if (!q)
  51.                 *q='\0';
  52.             strcpy (sysop, p);
  53.         }
  54.         if (!strnicmp("netmail", temp, 7)) {
  55.             p=skip_blanks(temp+7);
  56.             q=skip_to_blank(p);
  57.             if (!q)
  58.                 *q='\0';
  59.             strcpy (areas[0].area_file, p);
  60.             strcpy (areas[0].area_name, "FidoNetmail");
  61.             areas[0].lastread=areas[0].flags=0;
  62.         }
  63.     }
  64.     fclose (conf);
  65.     return TRUE;
  66. }
  67.  
  68. int readareas(void)
  69. {
  70.     FILE *conf;
  71.     char temp[100], *p, *q;
  72.     int  i;
  73.     
  74.     num_areas=1;
  75.     /* read areas.bbs */
  76.     sprintf (temp, "%s/areas.bbs", getenv("MAILER"));
  77.     conf=fopen(temp, "r");
  78.     if (conf==NULL)
  79.         return FALSE;
  80.     fgets (temp, 100, conf);    /* origin */
  81.     while (!feof(conf)) {
  82.         if (fgets (temp, 100, conf)==NULL) break;
  83.         if ((temp[0]==';') || (temp[0]=='-') || (temp[0]=='\n'))
  84.             temp[0]='\0';
  85.         if (temp[0]!='\0') {
  86.             p=skip_to_blank(temp);
  87.             *p='\0';
  88.             if ((!stricmp("passthru", temp)) || (!stricmp("mail", temp)))
  89.                 break;
  90.             strcpy (areas[num_areas].area_file, temp);
  91.             p=skip_blanks(p+1);
  92.             q=skip_to_blank(p);
  93.             if (q)
  94.                 *q=0;
  95.             strcpy (areas[num_areas].area_name, p);
  96.             areas[num_areas].flags=0;
  97.             areas[num_areas].lastread=0;
  98.             num_areas++;
  99.         }
  100.     }
  101.     fclose (conf);
  102.  
  103.     /* read led.new */
  104.     sprintf (temp, "%s/led.new", getenv("MAILER"));
  105.     conf=fopen(temp, "r");
  106.     if (conf==NULL)
  107.         return TRUE;
  108.        while (!feof(conf)) {
  109.            fgets (temp, 80, conf);
  110.            p=skip_to_blank(temp);
  111.            *p=0;
  112.            p=skip_blanks(p+1);
  113.            for (i=0; i<num_areas; i++)
  114.                if (!strcmp(temp, areas[i].area_name)) {
  115.                    areas[i].lastread=atoi(p);
  116.                    areas[i].flags=atoi(skip_blanks(skip_to_blank(p)));
  117.                }
  118.     }
  119.  
  120.     fclose (conf);
  121.     return TRUE;
  122. }
  123.